// by Xeno
#include <core_macros.h>

GVAR(NH_pnhuddo2_frskip) = GVAR(NH_pnhuddo2_frskip) + 1;
if (GVAR(NH_pnhuddo2_frskip) == 2) exitWith {
	GVAR(NH_pnhuddo2_frskip) = 0;
};
private ["_ct", "_txtar", "_ctrl", "_pre", "_unc", "_name", "_icon", "_color"];
disableSerialization;
if (!visibleMap && GVAR(NH_showNames)) then {
	_ct = cursorTarget;
	if (!isNull _ct && {_ct isKindOf "CAManBase"} && {alive _ct} && {((player getVariable ["BTC_need_revive",0]) == 0)} && {_ct != player} && {((positionCameraToWorld [0,0,0]) distance _ct) <= (GVAR(NH_dist_pname_hud) / 2)} && {side (group _ct) getFriend side (group player) >= 0.6}) then {
		_unc = !((_ct getVariable ["BTC_need_revive",0]) == 0);
		if (!_unc || GVAR(NH_display_unc)) then {
			GVAR(NH_pnhuddo_endtime) = time + 0.8;
			if (!GVAR(NH_showPlayerNameRSC_shown)) then {
				4769 cutRsc [QGVAR(NH_showPlayerNameRsc), "PLAIN"];
				GVAR(NH_showPlayerNameRSC_shown) = true;
				0 spawn FUNC(dosshowhuddospawn);
			};
			
			_txtar = [];
			_ctrl = (uiNamespace getVariable QGVAR(NH_showPlayerNameRsc)) displayCtrl 1000;
			_pre = if (group player == group _ct) then {
				_color = [0.6, 0.9, 0.6, 1];
				""
			} else {
				_color = GVAR(NH_friendly_color);
				""
			};
			
			_name = if (!_unc) then {if (isPlayer _ct) then {name _ct} else {getText(configFile/"CfgVehicles"/typeOf _ct/"displayName")}} else {localize "STR_X_NH_UNCON"};
			_txtar set [count _txtar, _pre + _name];
			_icon = getText(configFile/"CfgVehicles"/typeOf _ct/"Icon");
			if (_icon != "") then {
				_txtar set [count _txtar, image (getText(configFile/"CfgVehicleIcons"/_icon))];
			};
			if (getNumber(configFile/"CfgVehicles"/typeOf player/"attendant") == 1) then {
				_txtar set [count _txtar, lineBreak];
				_txtar set [count _txtar, "Damage: " + str(round ((damage _ct) * 90))];
			};
			_ctrl ctrlSetStructuredText composeText _txtar;
			_ctrl ctrlSetTextColor _color;
		};
	};
};